/*
 * @description: 
 * @Date: 2023-05-12 16:14:06
 * @example: 
 * @params: 
 */
const express = require("express");
const knex = require("../../db/config");
const Upload = express.Router();
const uploadAvatar = require('../../utils/multer/upload')
Upload.use(express.static(__dirname + "/www"));

/**
 * 图片上传
 * @route POST /img-upload
 * @group 上传 - Image Upload
 * @param {file} file.query.required - 请上传图片
 * @returns {object} 200 - An array of user info
 * @returns {Error}  default - Unexpected error
 */
Upload.post('/img-upload', async (req,res)=>{
    try {
        const uploadRes = await uploadAvatar(req, res)
        console.log(uploadRes);
        res.send({
          meta: { code: 200, msg: '上传成功！' },
          data: { id: uploadRes.id, img_url: uploadRes.img_url }
        })
      } catch (error) {
        res.send(error)
      }
})

module.exports = Upload